package com.webservice.impl;

import com.alibaba.fastjson.JSON;
import com.dao.EquipmentDao;
import com.dao.Maintenance_orderDao;
import com.dao.StatisticsDao;
import com.dao.UserDao;
import com.domain.Maintenance_order;
import com.domain.Maintenance_process;
import com.domain.User;
import com.tool.Until;
import com.webservice.StatisticsWebService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@WebService(targetNamespace = "http://39.98.59.6/mmms_test/ws/statistics")
public class StatisticsWebServiceImpl implements StatisticsWebService {


    @Autowired
    private Maintenance_orderDao maintenance_orderDao;

    @Autowired
    private StatisticsDao statisticsDao;

    @WebResult(name = "float")
    @Override
    public Float maintenancePriceOfEquipment(@WebParam(name = "equipment_id")Integer equipment_id) {
        Float price = statisticsDao.maintenancePriceOfEquipment(equipment_id);
        if (price == null){
            price = (float)0.00;
        }
        return price;

    }

    @WebResult(name = "float")
    @Override
    public Float maintenancePriceOfEquip() {
        Float price = statisticsDao.maintenancePriceOfEquip();
        if (price == null){
            price = (float)0.00;
        }
        return price;

    }

    @WebResult(name = "float")
    @Override
    public Float maintenancePriceOfEquipmentYear(@WebParam(name = "equipment_id")Integer equipment_id,
                                                 @WebParam(name = "year")String year) {


        Float price = statisticsDao.maintenancePriceOfEquipmentYear(equipment_id,Integer.valueOf(year.trim()));
        if (price == null){
            price = (float)0.00;
        }
        return price;
    }

    @WebResult(name = "float")
    @Override
    public Float maintenancePriceOfEquipYear(@WebParam(name = "year")String year) {

        Float price = statisticsDao.maintenancePriceOfEquipYear(Integer.valueOf(year.trim()));
        if (price == null){
            price = (float)0.00;
        }
        return price;
    }

    @WebResult(name = "integer")
    @Override
    public Integer maintenanceTimesOfEquipmentYear(@WebParam(name = "equipment_id")Integer equipment_id,
                                                   @WebParam(name = "year")String year) {

        Integer times = statisticsDao.maintenanceTimesOfEquipmentYear(equipment_id,Integer.valueOf(year.trim()));
        if (times == null){
            times = 0;
        }
        return times;
    }

    @WebResult(name = "integer")
    @Override
    public Integer maintenanceTimesOfEquipYear(@WebParam(name = "year")String year) {
        Integer times = statisticsDao.maintenanceTimesOfEquipYear(Integer.valueOf(year.trim()));
        if (times == null){
            times = 0;
        }
        return times;
    }

    @WebResult(name = "float")
    @Override
    public Float maintenancePriceOfInsiderUnit(@WebParam(name = "insiderUnit_id")Integer insiderUnit_id) {

        Float price = statisticsDao.maintenancePriceOfInsiderUnit(insiderUnit_id);
        if (price == null){
            price = (float)0.00;
        }
        return price;
    }

    @WebResult(name = "float")
    @Override
    public Float maintenancePriceOfInsiderUnitYear(@WebParam(name = "insiderUnit_id")Integer insiderUnit_id,
                                                   @WebParam(name = "year")String year) {

        Float price =  statisticsDao.maintenancePriceOfInsiderUnitYear(insiderUnit_id,Integer.valueOf(year.trim()));
        if (price == null){
            price = (float)0.00;
        }
        return price;
    }


    /**
     * 维修方的总维修次数和费用
     * @param
     * @return
     */
    @WebResult(name = "string")
    @Override
    public String maintenancePriceOfMaintenanceUnit() {
        Map<String, Object> map = new HashMap<>();
        Float price = statisticsDao.maintenancePriceOfMaintenanceUnit();
        if (price == null){
            price = (float)0.00;
        }
        Integer times = statisticsDao.maintenanceTimesOfMaintenanceUnit();
        if (times == null){
            times = (int)0;
        }
        map.put("price",price);
        map.put("times",times);
        return JSON.toJSONString(map);
    }

    /**
     * 维修方某年的维修次数和费用
     * @param
     * @param year
     * @return
     */
    @WebResult(name = "map")
    @Override
    public String maintenancePriceOfMaintenanceUnitYear(@WebParam(name = "year")String year) {
        Map<String, Object> map = new HashMap<>();
        Float price = statisticsDao.maintenancePriceOfMaintenanceUnitYear(Integer.valueOf(year.trim()));
        if (price == null){
            price = (float)0.00;
        }
        Integer times = statisticsDao.maintenanceTimesOfMaintenanceUnitYear(Integer.valueOf(year.trim()));
        if (times == null){
            times = (int)0;
        }
        map.put("price",price);
        map.put("times",times);
        return JSON.toJSONString(map);
    }

    /**
     * 某年的总维修费用和次数
     * @param year
     * @return
     */
    @WebResult(name = "map")
    @Override
    public String maintenancePriceAndTimes(@WebParam(name = "year")String year) {
        Map<String, Object> map = new HashMap<>();
        Float price = statisticsDao.maintenancePriceOfMaintenanceUnitYear(Integer.valueOf(year.trim()));
        if (price == null){
            price = (float)0.00;
        }
        Integer times = statisticsDao.maintenanceTimesOfMaintenanceUnitYear(Integer.valueOf(year.trim()));
        if (times == null){
            times = (int)0;
        }
        map.put("price",price);
        map.put("times",times);
        return JSON.toJSONString(map);
    }
}
